<?php

namespace Sffi\ElementPlus\ElForm;

use Sffi\ElementPlus\entity\Option;
use Sffi\ElementPlus\entityTrait\SelectOption;

class ElSelect extends FormItem
{
    use SelectOption;

    protected string $type = 'select';
    protected $placeholder;
    protected $remoteUrl;
    protected $optionKey;
    protected $optionVal;
    protected $multiple = 1;        //多选
    protected $tags = 0;            //标签模式
    protected $allowCreate = 0;     //允许创建

    public function __construct($title, $key, $placeholder = '请选择')
    {
        $this->title = $title;
        $this->key = $key;
        $this->prop = $key;
        $this->placeholder = $placeholder;
    }

    public function setTags($tags){
        $this->tags = $tags;
        return $this;
    }

    public function setAllowCreate($allowCreate){
        $this->allowCreate = $allowCreate;
        return $this;
    }

    public function setMultiple($multiple){
        $this->multiple = $multiple;
        return $this;
    }

    public function setRemoteUrl($url, $optionKey='', $optionVal=''){
        $this->remoteUrl = $url;
        $this->optionKey = $optionKey;
        $this->optionVal = $optionVal;
        return $this;
    }

    public function addOptionByArgs(string $key, string $value,bool $disabled=false, $children=[])
    {
        return $this->addOption(new Option($key, $value, $disabled, $children));
    }
}